﻿using Ext.Net;
using Ext.Net.MVC;
using Npgsql;
using PcaCore.DAL;
using PcaCore.DAL.Log;
using PcaCore.DAL.Pca;
using PcaPagos.BOL;
using PcaPagos.DAL;
using PcaReportes;
using PcaWeb.Models;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PcaWeb.Areas.Pagos.Controllers
{
    public class ReportesController : ControllerUser
    {
        public ActionResult GetAllOficinas(int start, int limit, string query)
        {
            int total;
            IEnumerable<object> records = dOficina.GetList(start, limit, out total, dSesion.GetEmpresaId(), query);
            return Json(new { data = records, total = total }, JsonRequestBehavior.AllowGet);
        }

        #region RptRegistrosPorOficina

        public ActionResult RptRegistrosPorOficina()
        {
            return View();
        }

        public FileResult GetRptRegistrosPorOficina(string oficinaId, DateTime? fechaInicio, DateTime? fechaFin, int? filtroId)
        {
            string rptFile = Server.MapPath("~/Rpt/RptRegistrosPorOficina.rdl");
            ListDictionary ld = new ListDictionary();
            ld.Add("cnn", Core.GetConnectionString()); 
            ld.Add("empresaId", dSesion.GetEmpresaId());
            ld.Add("oficinaId", oficinaId);
            ld.Add("fechaInicio", fechaInicio);
            ld.Add("fechaFin", fechaFin);
            ld.Add("filtroId", filtroId);

            RdlReport rpt = new RdlReport(rptFile, ld);

            Response.AppendHeader("content-disposition", String.Format("inline; filename={0}.pdf", rpt.GetNombreReporte));
            return File(rpt.GetBytesPdf, "application/pdf");
        }

        #endregion
    }
}